#include "ParticleTest.h"
#include "CustomParticleTest.h"

USING_NS_CC;

cocos2d::Scene* ParticleTest::createScene() {
        auto scene = Scene::create();

        auto layer = ParticleTest::create();

        if (layer) {
                scene->addChild(layer);
        }

        return scene;
}

bool ParticleTest::init() {
        if (!Layer::init()) {
                return false;
        }
        //auto listener = EventListenerKeyboard::create();
        //listener->onKeyPressed = CC_CALLBACK_2(ParticleTest::onKeyPressed, this);
        //_eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this);

        setKeyboardEnabled(true);
        return true;
}

void ParticleTest::onKeyPressed(EventKeyboard::KeyCode keyCode, Event* event) {
        removeAllChildren();
        auto visibleSize = Director::getInstance()->getVisibleSize();
        auto origin = Director::getInstance()->getVisibleOrigin();

        ParticleSystem * particle(nullptr);
        switch ( keyCode ) {
        case EventKeyboard::KeyCode::KEY_1:
                particle = ParticleFire::create();
                break;
        case EventKeyboard::KeyCode::KEY_2:
                particle = ParticleFireworks::create();
                break;
        case EventKeyboard::KeyCode::KEY_3:
                particle = CustomParticleTest::create();

                break;
        case EventKeyboard::KeyCode::KEY_4:
                particle = ParticleFlower::create();
                break;
        case EventKeyboard::KeyCode::KEY_5:
                particle = ParticleGalaxy::create();
                break;
        case EventKeyboard::KeyCode::KEY_6:
                particle = ParticleMeteor::create();
                break;
        case EventKeyboard::KeyCode::KEY_7:
                particle = ParticleRain::create();
                break;
        case EventKeyboard::KeyCode::KEY_8:
                particle = ParticleSmoke::create();
                break;
        case EventKeyboard::KeyCode::KEY_9:
                particle = ParticleSnow::create();
                break;
        case EventKeyboard::KeyCode::KEY_0:
                particle = ParticleSpiral::create();
                break;
        default:
                particle = ParticleSun::create();
                break;
        }
        if (particle) {
                particle->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2));
                addChild(particle);
        }
}
